package com.tanhua.controller;

import com.tanhua.service.CommentsService;
import lombok.extern.slf4j.Slf4j;
import model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
@Slf4j
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    //分页查询评理列表
    @GetMapping
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String movementId) {
        PageResult pageResult = commentsService.findComments(movementId, page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    @PostMapping
    public ResponseEntity saveComments(@RequestBody Map map){
        String movementId = (String )map.get("movementId");
        String comment = (String)map.get("comment");
        commentsService.saveComments(movementId,comment);
        return ResponseEntity.ok(null);
    }
}